using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Data.Models.Mapping
{
    public class ToolDetailMap : EntityTypeConfiguration<ToolDetail>
    {
        public ToolDetailMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.Code)
                .HasMaxLength(20);

            // Table & Column Mappings
            this.ToTable("ToolDetails");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.Code).HasColumnName("Code");
            this.Property(t => t.OrderID).HasColumnName("OrderID");
            this.Property(t => t.ProductModelID).HasColumnName("ProductModelID");
            this.Property(t => t.ToolFormulaID).HasColumnName("ToolFormulaID");
            this.Property(t => t.ToolTypeID).HasColumnName("ToolTypeID");
            this.Property(t => t.UOM1ID).HasColumnName("UOM1ID");
            this.Property(t => t.Quantity).HasColumnName("Quantity");
            this.Property(t => t.ToolNormID).HasColumnName("ToolNormID");
            this.Property(t => t.UOMID2).HasColumnName("UOMID2");
            this.Property(t => t.Norm).HasColumnName("Norm");

            // Relationships
            this.HasRequired(t => t.Order)
                .WithMany(t => t.ToolDetails)
                .HasForeignKey(d => d.OrderID);
            this.HasOptional(t => t.ProductModel)
                .WithMany(t => t.ToolDetails)
                .HasForeignKey(d => d.ProductModelID);
            this.HasOptional(t => t.ToolFormula)
                .WithMany(t => t.ToolDetails)
                .HasForeignKey(d => d.ToolFormulaID);
            this.HasOptional(t => t.ToolNorm)
                .WithMany(t => t.ToolDetails)
                .HasForeignKey(d => d.ToolNormID);
            this.HasOptional(t => t.ToolType)
                .WithMany(t => t.ToolDetails)
                .HasForeignKey(d => d.ToolTypeID);
            this.HasOptional(t => t.UOM)
                .WithMany(t => t.ToolDetails)
                .HasForeignKey(d => d.UOM1ID);
            this.HasOptional(t => t.UOM1)
                .WithMany(t => t.ToolDetails1)
                .HasForeignKey(d => d.UOMID2);

        }
    }
}
